/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: PageQueryMapperInvoke.java   2020-09-30 09-21-20
 * Author: Evan
 */
package cn.datacare.orm.mapper.inovke;

import cn.datacare.orm.manager.impl.SQLManager;
import cn.datacare.orm.mapper.MapperInvoke;
import cn.datacare.orm.mapper.MethodDesc;
import cn.datacare.orm.mapper.parameter.PageQueryParameter;
import cn.datacare.orm.query.PageQuery;

import java.lang.reflect.Method;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-09-30 09-21-20
 * @since V1.0
 */
public class PageQueryMapperInvoke implements MapperInvoke {

    @Override
    public Object call(SQLManager sm, Class entityClass, String sqlId, Method m, Object[] args) {
        MethodDesc desc = MethodDesc.getMethodDescBySqlId(sm,entityClass,m,sqlId);
        PageQueryParameter parameter = (PageQueryParameter)desc.parameter;
        Class returnType = m.getReturnType();
        PageQuery query = (PageQuery)parameter.get(args);
        sm.pageQuery(sqlId, desc.resultType, query);
        if(returnType==PageQuery.class){
            return query;
        }else{
            return null;
        }
    }
}
